package com.hfjava.practice03;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: com.hfjava.practice03
 * @ClassName: IssuePapers
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/26 19:37
 * @Copyright 大牛版板所有
 */
public class IssuePapers implements Runnable {

    private Papers papers = new Papers();

    @Override
    public void run() {
        for (int i = 0; i < 30; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            issue();
        }
    }


    private synchronized void issue() {
        if (papers.getNum() > 0){
            int number = papers.isp();
            System.out.println(Thread.currentThread().getName()+"发1张试卷，剩余试卷："+number+"章");
        }

    }


    public static void main(String[] args) {
        IssuePapers isu = new IssuePapers();
        Thread t1 = new Thread(isu);
        t1.setName("张老师");
        Thread t2 = new Thread(isu);
        t2.setName("李老师");
        Thread t3 = new Thread(isu);
        t3.setName("王老师");

        t1.start();
        t2.start();
        t3.start();
    }
}
